<template>
    <div>
        <el-card class="card">
            <template #header>
                <div class="section-title">
                    基本信息
                </div>
            </template>
            <div class="row">
                <div class="item">
                    <div class="label">单位名称：</div>
                    <div class="value">{{ unitInfo.name }}</div>
                </div>
            </div>
            <div class="row" style="margin: 16px 0;">
                <div class="item">
                    <div class="label">单位地址：</div>
                    <div class="value">{{ unitInfo.address }}</div>
                </div>
                <div class="item">
                    <div class="label">负责人：</div>
                    <div class="value">{{ unitInfo.leader }}</div>
                </div>
                <div class="item">
                    <div class="label">单位职级：</div>
                    <div class="value">{{ unitInfo.rankNmae }}</div>
                </div>
            </div>
            <div class="row">
                <div class="item">
                    <div class="label">单位类别: </div>
                    <div class="value">{{ unitInfo.unitTypeNmae }}</div>
                </div>
                <div class="item">
                    <div class="label">三定人数：</div>
                    <div class="value">{{ unitInfo.thirdNums }}</div>
                </div>
                <div class="item">
                    <div class="label">实有人数：</div>
                    <div class="value">{{ unitInfo.realNums }}</div>
                </div>
            </div>
            <div class="section-title" style="border-bottom:1px solid #e4e7ed;margin: 36px 0;">
                单位基本办公用房面积分析
            </div>
            <el-table :data="tableData">
                <el-table-column align="left" label="用房类型" prop="roomType"></el-table-column>
                <el-table-column align="left" label="实际使用面积" prop="realArea"></el-table-column>
                <el-table-column align="left" label="核定面积" prop="approveArea"></el-table-column>
                <el-table-column align="left" label="超标面积" prop="exceedArea"></el-table-column>
            </el-table>
            <div class="section-title" style="border-bottom:1px solid #e4e7ed;margin: 36px 0;">
                单位办公用房超标原因
            </div>
            <el-form>
                <el-form-item label="备注" prop="notes">
                    <el-input v-model="form.reason" type="textarea" :rows="6" />
                </el-form-item>
            </el-form>
            <div class="btn-box">
                <el-button class="btn" type="primary" @click="onSubmit">保存</el-button>
            </div>
        </el-card>
    </div>
</template>

<script setup>
import { reactive, ref, onMounted } from 'vue'
import { useUserStore } from '@/pinia/modules/user'
import { useStorage } from '@vueuse/core'
import {
    getDyList
} from '@/api/xitongpeizhi'
import {
    unitBaseInfo,
    roomExceed,
    exceedReason
} from '@/api/unit'
import {
    getZjList
} from '@/api/xitongpeizhi'
import { ElMessage, ElMessageBox, useFormItem } from 'element-plus'
const userStore = useUserStore()

defineOptions({
    name: 'Dashboard'
})

const form = ref({
    reason: '',
    unitId: JSON.parse(localStorage.getItem('userInfo')).unitId
})

const tableData = ref([])
const unitInfo = ref({})
const lbList = ref([])
const zjList = ref([])
onMounted(() => {
    if (localStorage.getItem('userInfo')) {
        form.value.unitId = JSON.parse(localStorage.getItem('userInfo')).unitId
    }
    unitBaseInfo().then(res1 => {
        getDyList({ pageNumber: 1, pageSize: 100 }).then(res2 => {
            getZjList({ pageNumber: 1, pageSize: 100 }).then(res3 => {
                zjList.value = res3.result.data
                lbList.value = res2.result.data.filter(item => item.type == 2)
                unitInfo.value = res1.result
                unitInfo.value.unitTypeNmae = lbList.value.find(m => m.id == res1.result.unitType).name
                unitInfo.value.rankNmae = zjList.value.find(m => m.id == res1.result.rank).name
            })
        })
    })

    roomExceed().then(res => {
        tableData.value = res.result
    })
})
const onSubmit = () => {
    exceedReason(form.value).then(res => {
        if (res.code == 200) {
            ElMessage({
                type: 'success',
                message: '保存成功!'
            })
        }
    })
}
</script>

<style lang="scss" scoped>
.section-title {
    font-weight: bold;
    font-size: 18px;
    line-height: 33px;
    padding-left: 14px;
    color: #4E7DF7;
    position: relative;
}

.section-title:before {
    content: '';
    position: absolute;
    top: 10px;
    left: 0;
    width: 6px;
    height: 14px;
    border-radius: 3px;
    background: #4E7DF7;
}

.card {
    .row {
        display: flex;

        .item {
            display: flex;
            width: 30%;
        }
    }

    .btn-box {
        display: flex;
        justify-content: center;
    }

    .btn {
        margin: 0;
        margin-left: auto;
        margin-right: auto;
        width: 100px;
    }
}
</style>